const Router = require('koa-router');
const login = new Router();


//！拿到前端的数据
//数据库连接池
const pg = require('pg');
let psql = new pg.Pool({
    database: 'running',
    user: 'run',
    port: 5432,
    host: '82.157.94.115',
    password: 'z12345678',
    max: 2
})

login.post('/login', async ctx => {
    let { username, password } = ctx.request.body;
    console.log('用户名', username);
    console.log('密码', password);
    let searchPasswordPostgresql = `SELECT password FROM login WHERE username='${username}';`
    let content = await psql.query(searchPasswordPostgresql);
    console.log(content.rows[0].password);
    if (content.rows[0].password === password) {
        //ctx.status = 200;
        // ctx.res.statusCode = 200;
        ctx.body = {
            msg: "登录成功",
            username: username,
            password: password
        }
        
    }
    // else{
    //     ctx.body = {
    //         msg: "登录失败",
    //     }
    // } 
}



)
module.exports = login;

